//
//  LoginAndRegisterViewController.m
//  MingJiangApp
//
//  Created by wangliang on 15/3/9.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "LoginAndRegisterViewController.h"
#import "ResigterAllViewController.h"
#import "FindPasswordViewController.h"

#import "UMSocialDataService.h"

@interface LoginAndRegisterViewController ()

@end

@implementation LoginAndRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = Color_Back_Black;
    
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (IBAction)forgetBtn:(id)sender {
    
    FindPasswordViewController *findPasswordVC = [[FindPasswordViewController alloc] init];
    findPasswordVC.title = @"找回密码";
    [self.navigationController pushViewController:findPasswordVC animated:YES];
}

- (IBAction)close:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)login:(id)sender {
    
    [self.navigationController pushViewController:[[LoginViewController alloc] init] animated:YES];
}

- (IBAction)register:(id)sender {
    
    [self.navigationController pushViewController:[[ResigterAllViewController alloc] init] animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)sinaLogIn:(id)sender {
    
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response) {
    
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        dic[@"type"] = @"2";
        dic[@"open_id"] = response.data[@"sina"][@"usid"];
        dic[@"nickName"] = response.data[@"sina"][@"username"];
        dic[@"head"] = response.data[@"sina"][@"icon"];
        [self postData:dic];
    });
    
}

- (IBAction)tencentLogIn:(id)sender {
    //    return;
    
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
    });
}
- (void)postData:(NSDictionary *)dic {
    
    [WLHttpRequestAfter userLoginAuthoWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        
        if ([resultDictionary[@"status"] integerValue] == 1) {
            
            [userInfoTool updateInfo:resultDictionary[@"data"]];
            [self dismissViewControllerAnimated:YES completion:nil];
            [[NSNotificationCenter defaultCenter] postNotificationName:K_NOTICE_MINE object:nil];
        }
    } andFailureBlock:^(NSError *resultError) {
        
    }];
}

@end
